﻿using CNKI.TPI.Web.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CNKI.TPI.Web.UI
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes, string sitename)
        {
            string ctrl = "Home";
            string act = "Index";
            int _topiccode = 1;
            IDataContext context = new DataContext();
            DataTable dt= context.ExecuteSql("SELECT * FROM SYS_CMS_TOPIC WHERE DOMAIN='" + sitename + "'");
            if (dt != null & dt.Rows.Count > 0)
            {
                ctrl = "Topic";
                _topiccode = Convert.ToInt32(dt.Rows[0]["SYSID"]);
            }

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{_topiccode}",
                defaults: new { controller = ctrl, action = act, _topiccode= _topiccode }
            );
        }
    }
}